<template>
  <div>
    <div class="pdt20"></div>
    <van-cell-group inset class="mgt20">
      <van-cell title="名称" :value="detailInfo.Name" />
      <van-cell title="手机号码" :value="detailInfo.Phone" />
      <van-cell
        title="班级"
        v-if="detailInfo.Type == 1"
        :value="detailInfo.Name_Class"
      />
      <van-cell
        title="部门"
        v-if="detailInfo.Type != 1"
        :value="detailInfo.Name_Dept"
      />
      <van-cell title="籍贯" :value="detailInfo.Ancestral" />
      <van-cell title="民族" :value="detailInfo.Nation" />
      <van-cell title="出生日期" :value="detailInfo.Birthday" />
      <van-cell title="学历" :value="detailInfo.Education" />
      <van-cell title="入学日期" :value="detailInfo.AccessionDate" />
      <van-cell title="邮箱" :value="detailInfo.Email" />
      <van-cell title="性别" :value="detailInfo.Sex" />
      <van-cell title="用户类型" :value="detailInfo.TypeName" />
      <van-cell title="备注" :value="detailInfo.Remark" />
    </van-cell-group>
    <div class="mgb20"></div>
    <div class="pad10">
      <van-button round type="primary" block @click="handleUpdatePWD"
        >修改密码</van-button
      >
    </div>
    <div class="pad10">
      <van-button round type="danger" block @click="logout"
        >解除绑定</van-button
      >
    </div>
  </div>
</template>

<script setup name="InformationM">
import useUserStore from '@/store/modules/user';
import { computed, getCurrentInstance } from 'vue';
import { useRouter } from 'vue-router';
import { UnBindAccount } from '@/api/wx/index.js';
import { GetUserDetail } from '@/api/system/user';
const router = useRouter();
const { proxy } = getCurrentInstance();
const userStore = useUserStore();
const userInfo = computed(() => userStore.userInfo);
const detailInfo = ref({});
const UserType = {
  1: '学员',
  2: '职员',
  3: '管理员'
};

onMounted(() => {
  getUserInfo();
});

async function getUserInfo() {
  try {
    let res = await GetUserDetail({ ID: userInfo.value.ID });
    detailInfo.value = {
      ...res.data?.Info,
      AccessionDate: res.data?.Info?.AccessionDate?.slice(0, 10),
      Birthday: res.data?.Info?.Birthday?.slice(0, 10),
      TypeName: UserType[res.data?.Info?.Type]
    };
  } catch (error) {
    console.log(error);
  }
}

async function logout() {
  try {
    await proxy.$modal.mDialog({ message: '确认解除绑定吗？' });
    await UnBindAccount();
    await userStore.logOut();
    router.push({ path: '/login', query: { state: 'bind' } });
    // location.replace('/');
  } catch (error) {
    console.log(error);
  }
}
function handleUpdatePWD() {
  router.push('/PassWord');
}
</script>

<style lang="scss" scoped></style>
